package com.wf.smartcomm.server.bean;


import java.math.BigDecimal;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.google.gson.annotations.Expose;
import com.wf.smartcomm.server.util.IdUtils;
import com.wf.smartcomm.server.util.StringUtil;

/**
 * @author 38884306@qq.com
 * @version ����ʱ�䣺2015-5-18 ����10:14:09
 * 
 */
@Entity
@Table(name = "t_user")
public class User {
	@Expose
	@Id
	@Column(length = 32)
	private String objectId;
	
	@Expose
	@Column(length = 16)
	private String pushId;

	@Expose
	@Column(length = 32)
	private String username;

	@Column(length = 64)
	private String password;

	@Expose
	@Column(length = 1)
	private String gender;

	@Expose
	@Column(length = 16)
	private String name;

	@Expose
	@Column(length = 32)
	private String nick;

	@Expose
	@Column(length = 32)
	private String email;
	
	@Column(length = 32)
	private String openId;
	
	@Column(length = 64)
	private String access_token;
	
	@Column(length = 32)
	private String expires_in;
	
	@Column(length = 32)
	private String token;

	@Expose
	@Column(length = 4096)
	private String avatar;

	@Expose
	@Column(length = 20)
	private String phoneNumber;

	@Expose
	@Column(length = 64)
	private String id;
	
	@Expose
	@Column(length = 64)
	private String appleToken;
	
	@Expose
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "parent_id")
	private User parent;

	@Expose
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "vid")
	private Village loginVillage;

	@Expose
	@Column(length = 1)
	private String type;//身份类型
	
	@Column(length = 1)
	private Integer userType;//用户类型 -app weixin

	@Expose
	@Column(length = 1)
	private String isUnReg;

	@Expose
	@Column(length = 1)
	private String priority;

	@Expose
	@Column(length = 1)
	private String isAdmin;

	@Expose
	@Column(length = 1)
	private String pushAble;
	
	@Expose
	@Column
	private Integer isActivated;
	
	@Expose
	@Column
	private BigDecimal totalScore = BigDecimal.ZERO;
	
	@Expose
	@Column
	private BigDecimal totalAmount = BigDecimal.ZERO;
	
	@Expose
	@Column(length = 1)
	private String deviceType;
	
	@ManyToMany
	@JoinTable(name = "t_user_relation_village", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns = { @JoinColumn(name = "vid") })
	private Set<Village> villages;

	@Expose
	@Column(length = 32)
	private String voipAccount;
	
	@Expose
	@Column(length = 32)
	private String voipPwd;
	
	@Expose
	@Column(length = 32)
	private String subAccountSid;
	
	@Expose
	@Column(length = 32)
	private String subToken;
	
	@Column(length = 20)
	private String createdAt;

	@Column(length = 20)
	private String updateAt;
	
	@Column(length = 20)
	private String notifyDate;
	
	@Column(length = 64)
	private String deviceToken;
	
	@Column
	private Integer loginState;
	
	@Expose
	@Column
	private Integer isCenterUser;

	@ManyToMany
	@JoinTable(name = "t_user_relation_house", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns = { @JoinColumn(name = "hid") })
	private Set<House> houses;
	
	public User(String objectId) {
		this.objectId = objectId;
	}
	
	public User(){
		
	}

	public Integer getIsCenterUser() {
		return isCenterUser;
	}

	public void setIsCenterUser(Integer isCenterUser) {
		this.isCenterUser = isCenterUser;
	}

	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = totalAmount;
	}

	public String getDeviceToken() {
		return deviceToken;
	}

	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
	}

	public Village getSelectedVillage() {
		return loginVillage;
	}

	public void setSelectedVillage(Village loginVillage) {
		this.loginVillage = loginVillage;
	}

	public String getEmail() {
		return email;
	}

	public String getVoipAccount() {
		return voipAccount;
	}

	public void setVoipAccount(String voipAccount) {
		this.voipAccount = voipAccount;
	}

	public String getVoipPwd() {
		return voipPwd;
	}

	public void setVoipPwd(String voipPwd) {
		this.voipPwd = voipPwd;
	}

	public String getSubAccountSid() {
		return subAccountSid;
	}

	public void setSubAccountSid(String subAccountSid) {
		this.subAccountSid = subAccountSid;
	}

	public String getSubToken() {
		return subToken;
	}

	public void setSubToken(String subToken) {
		this.subToken = subToken;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Set<House> getHouses() {
		return houses;
	}

	public void setHouses(Set<House> houses) {
		this.houses = houses;
	}

	public String getObjectId() {
		return objectId;
	}

	public void setObjectId(String objectId) {
		this.objectId = objectId;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public User getParent() {
		return parent;
	}

	public void setParent(User parent) {
		this.parent = parent;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getIsUnReg() {
		return isUnReg;
	}

	public void setIsUnReg(String isUnReg) {
		this.isUnReg = isUnReg;
	}

	public String getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(String createdAt) {
		this.createdAt = createdAt;
	}

	public String getPushAble() {
		return pushAble;
	}

	public void setPushAble(String pushAble) {
		this.pushAble = pushAble;
	}

	public String getUpdateAt() {
		return updateAt;
	}

	public void setUpdateAt(String updateAt) {
		this.updateAt = updateAt;
	}

	public String getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(String isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public Village getLoginVillage() {
		return loginVillage;
	}

	public void setLoginVillage(Village loginVillage) {
		this.loginVillage = loginVillage;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	public void updateInfo(User user) {
		if (!StringUtil.isEmpty(user.email)) {
			email = user.email;
		}
		if (!StringUtil.isEmpty(user.gender)) {
			gender = user.gender;
		}
		if (!StringUtil.isEmpty(user.nick)) {
			nick = user.nick;
		}
		if (!StringUtil.isEmpty(user.phoneNumber)) {
			phoneNumber = user.phoneNumber;
		}
		if (!StringUtil.isEmpty(user.id)) {
			id = IdUtils.MD5(user.id);
		}
		if (!StringUtil.isEmpty(user.name)) {
			name = user.name;
		}
	}
	
	public String getDeviceType() {
		return deviceType;
	}

	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

	public String getAppleToken() {
		return appleToken;
	}

	public void setAppleToken(String appleToken) {
		this.appleToken = appleToken;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getPushId() {
		return pushId;
	}

	public void setPushId(String pushId) {
		this.pushId = pushId;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Integer getUserType() {
		return userType;
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}

	public String getAccess_token() {
		return access_token;
	}

	public void setAccess_token(String access_token) {
		this.access_token = access_token;
	}

	public String getExpires_in() {
		return expires_in;
	}

	public void setExpires_in(String expires_in) {
		this.expires_in = expires_in;
	}

	public Set<Village> getVillages() {
		return villages;
	}

	public void setVillages(Set<Village> villages) {
		this.villages = villages;
	}

	public String getNotifyDate() {
		return notifyDate;
	}

	public void setNotifyDate(String notifyDate) {
		this.notifyDate = notifyDate;
	}

	public Integer getIsActivated() {
		return isActivated;
	}

	public void setIsActivated(Integer isActivated) {
		this.isActivated = isActivated;
	}

	public Integer getLoginState() {
		return loginState;
	}

	public void setLoginState(Integer loginState) {
		this.loginState = loginState;
	}

	public BigDecimal getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(BigDecimal totalScore) {
		this.totalScore = totalScore;
	}
}
